﻿@using System.Web.Globalization
@using QAS.Nekorama.Common
@using QAS.Nekorama.Models
@using Resources
@model QuestionDetailModel
@{
    int currentuser = 0;
    if (User.Identity.IsAuthenticated)
    {
        currentuser = ViewBag.CurrentUserInfo.UserID;
    }
    ViewBag.Title = QAS_Nekorama.QUESTIONS;
}

<script src="~/Scripts/jquery.validationEngine.js"></script>
<script src="~/Scripts/jquery.validationEngine-en.js"></script>
<link href="~/Content/jquery-te-1.4.0.css" rel="stylesheet" />
<script src="~/Scripts/jquery-te-1.4.0.min.js"> </script>
<link href="~/Content/validationEngine.jquery.css" rel="stylesheet" />

@if (Model.Question.IsSpam == false && Model.Question.IsDeleted == false)
{
    <div id="primary">
        <div id="primary-1">
            <!--ERROR LIST-->
            @if (Model.Failures != null && Model.Failures.Count > 0)
            {
                <div class="error-list">
                    <ul>
                        @foreach (var err in Model.Failures)
                        {
                            <li>@err.ErrorMessage</li>
                        }
                    </ul>
                    @if (TempData["error"] != null)
                    {
                        <ul>
                            <li>@TempData["error"]</li>
                        </ul>
                    }
                </div>
                <!--end error-list-->}
            <!--Question Title-->
            <h1 style="word-wrap: break-word">@Model.Question.Title</h1>
        </div>
        <!--end primary-1-->

        <div id="primary-2">
            <div id="a-question">
                <div class="post-info">
                    <div class="profile">
                        <a href="@Url.Action("Details", "User", new {id = Model.Question.CreatedUser}, null)">
                            <img src="/Images/Avatars/@Helper.GetUserInfo(Model.Question.CreatedUser).Avatar" /></a>
                        <h4>@Html.ActionLink(Helper.GetUserInfo(Model.Question.CreatedUser).DisplayName, "Details", "User", new {id = Model.Question.CreatedUser}, null)</h4>
                    </div>
                    <!--end profile-picture-->

                    <div class="rate">
                        @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && ViewBag.CurrentUserInfo.Reputation >= 
                            (int) Constants.Privileges.VoteDown && WebSecurity.CurrentUserId != Model.Question.CreatedUser)
                        {
                            if (!Helper.IsInString(WebSecurity.CurrentUserId, Model.Question.VoteUpUserList))
                            {
                            <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" onclick=" vote(@Model.Question.QuestionID, true, true) " />
                            }
                            else
                            {
                            <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" style="-webkit-filter: grayscale(0);" />
                            }

                            <p>@Model.Question.VoteCount</p>
                            if (!Helper.IsInString(WebSecurity.CurrentUserId, Model.Question.VoteDownUserList))
                            {
                            <img src="/Images/Question-Details/votedown.png" class="votedown-btn" onclick=" vote(@Model.Question.QuestionID, false, true) " />
                            }
                            else
                            {
                            <img src="/Images/Question-Details/votedown.png" class="votedown-btn" style="-webkit-filter: grayscale(0);" />
                            }
                        }
                        else if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && ViewBag.CurrentUserInfo.Reputation >= 
                                (int) Constants.Privileges.VoteUp && WebSecurity.CurrentUserId != Model.Question.CreatedUser)
                        {
                            if (!Helper.IsInString(WebSecurity.CurrentUserId, Model.Question.VoteUpUserList))
                            {
                            <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" onclick=" vote(@Model.Question.QuestionID, true, true) " />
                            }
                            else
                            {
                            <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" style="-webkit-filter: grayscale(0);" />
                            }
                            <p>@Model.Question.VoteCount</p>
                            <img src="/Images/Question-Details/votedown.png" class="votedown-btn" style="-webkit-filter: grayscale(0);" />
                        }
                        else
                        {
                            <img src="/Images/Question-Details/voteup.png" class="voteup-btn" style="-webkit-filter: grayscale(0);" />
                            <p>@Model.Question.VoteCount</p>
                            <img src="/Images/Question-Details/votedown.png" class="votedown-btn" style="-webkit-filter: grayscale(0);" />
                        }
                    </div>
                    <!--end rate-->

                    <div class="page-view">
                        <p>@Model.Question.ViewCount @QAS_Nekorama.VIEW</p>
                        @for (int i = 0; i < Model.Question.SpamCount; i++)
                        {
                            <img title="@QAS_Nekorama.REPORTED" src="~/Images/Question-Details/report-img.png" style="width: 30px;" />
                        }
                    </div>
                    <!--end page-view-->
                </div>
                <!--end post-info-->

                <div class="post-detail">
                    <!--Question information-->
                    <p style="font-size: 10px; font-style: italic;">@Html.ActionLink(Helper.GetUserInfo(Model.Question.CreatedUser).DisplayName, 
                        "Details", "User", new {id = Model.Question.CreatedUser}, null) @QAS_Nekorama.CREATE_TIME @Model.Question.CreatedDate</p>

                    <div style="min-height: 160px; margin-bottom: 15px;">
                    <!--Question content-->
                    @if (Model.Question.Content.Contains("<p"))
                    {
                        @Html.Raw(Model.Question.Content)
                    }
                    else
                    {
                            @Html.Raw(Model.Question.Content)
                    }
                        </div>
                    <!--Question tags-->
                    <ul class="tags">
                        @if (Model.Question.TagName1 != null && !Model.Question.TagName1.IsEmpty())
                        {
                            <li>@Html.ActionLink("#" + Model.Question.TagName1, "Index", "Question", new {searchString = "#" + Model.Question.TagName1}, null)</li>
                        }
                        @if (Model.Question.TagName2 != null && !Model.Question.TagName2.IsEmpty())
                        {
                            <li>@Html.ActionLink("#" + Model.Question.TagName2, "Index", "Question", new {searchString = "#" + Model.Question.TagName2}, null)</li>
                        }
                        @if (Model.Question.TagName3 != null && !Model.Question.TagName3.IsEmpty())
                        {
                            <li>@Html.ActionLink("#" + Model.Question.TagName3, "Index", "Question", new {searchString = "#" + Model.Question.TagName3}, null)</li>
                        }
                        @if (Model.Question.TagName4 != null && !Model.Question.TagName4.IsEmpty())
                        {
                            <li>@Html.ActionLink("#" + Model.Question.TagName4, "Index", "Question", new {searchString = "#" + Model.Question.TagName4}, null)</li>
                        }
                        @if (Model.Question.TagName5 != null && !Model.Question.TagName5.IsEmpty())
                        {
                            <li>@Html.ActionLink("#" + Model.Question.TagName5, "Index", "Question", new {searchString = "#" + Model.Question.TagName5}, null)</li>
                        }
                    </ul>
                    <!--end tags-->
                </div>
                <!--end post-detail-->

                <!--COMMENT-->
                @if (Model.Comments.Count != 0)
                {
                    <div class="comment_list">
                        <div class="accordion">
                            <h3>@QAS_Nekorama.COMMENT_S</h3>
                            <div>
                                @foreach (Comment c in Model.Comments)
                                {
                                    <div class="comment">
                                        <h1>@Html.ActionLink(Helper.GetUserInfo(c.CreatedUser).DisplayName, "Details", "User", new {id = c.CreatedUser}, null)</h1>
                                        <p style="word-wrap: break-word">@Html.Raw(Helper.Html2Text(c.Content))</p>
                                    </div>
                                    <!--end comment-->
                                }
                                @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Comment)
                                {
                                    <div class="comment_tools">
                                        <textarea class="post-content" placeholder='@QAS_Nekorama.ENTER_COMMENT' name="comment-textbox" cols="70" rows="3" id="question-comment-content"></textarea>
                                        @Html.ActionLink(QAS_Nekorama.COMMENT, null, null, new {@class = "comment-btn", @onclick = "postComment(null,event);"})
                                    </div>
                                    <!--end comment_tools-->
                                }
                            </div>
                        </div>
                        <!--end accordion-->
                    </div>
                    <!--end comment_list-->
                }
                else
                {
                    if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Comment)
                    {
                    <div class="comment_list">
                        <div class="accordion">
                            <h3>@QAS_Nekorama.COMMENT_S</h3>
                            <div>
                                    @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Comment)
                                {
                                    <div class="comment_tools">
                                        <textarea class="post-content" placeholder='@QAS_Nekorama.ENTER_COMMENT' name="comment-textbox" cols="70" rows="3" id="question-comment-content" ></textarea>
                                            @Html.ActionLink(QAS_Nekorama.COMMENT, null, null, new {@class = "comment-btn", @onclick = "postComment(null,event);"})
                                    </div>
                                    <!--end comment_tools-->
                                }
                            </div>
                        </div>
                        <!--end accordion-->
                    </div>
                    <!--end comment_list-->
                    }
                }
                <!--END COMMENT-->

                <div class="manage">
                    <!--SET BOUNTY-->
                    @if (!Helper.HasAcceptedAnswer(Model.Question.QuestionID) && User.Identity.IsAuthenticated && 
                        Model.Bounty == null && ViewBag.CurrentUserInfo.BanDuration == 0 && ViewBag.CurrentUserInfo.Reputation >= 
                        (int) Constants.Privileges.SetBounty)
                    {
                        <div class="bounty">
                            <form id="bountyform">
                            @Html.ActionLink(QAS_Nekorama.SET_BOUNTY, null, null, 
                                new {@class = "set-bounty-btn", id = "set-bounty-btn", onclick = "setbounty(event);", style = "margin-left: 10px;"})
                                <input type="text" name="set bounty" placeholder='@QAS_Nekorama.BOUNTY' id="bountyamount" />
                            </form>
                        </div>
                        <!--end bounty-->
                    }
                    else
                    {
                        if (Model.Question.BountyID != null)
                        {
                            if (Model.Bounty.Duration == 0)
                            {
                        <div class="bounty">
                            <img src="~/Images/Question-Details/bounty-img.png" style="-webkit-filter: grayscale(100%);" />
                            <p>@QAS_Nekorama.BOUNTY (@Model.Bounty.Amount) @QAS_Nekorama.COMPLETED_ON @Model.Bounty.LastModifiedDate.Value.Day|
                                @Model.Bounty.LastModifiedDate.Value.Month|@Model.Bounty.LastModifiedDate.Value.Year</p>
                        </div>
                        <!--end bounty-->
                            }
                            else
                            {
                        <div class="bounty">
                            <img src="~/Images/Question-Details/bounty-img.png" />
                            <p>@QAS_Nekorama.BOUNTY: (@Model.Bounty.Amount)- @Model.Bounty.Duration @QAS_Nekorama.DAY_LEFT </p>
                        </div>
                        <!--end bounty-->
                            }

                        }

                    }
                    <!--END BOUNTY-->

                    <div class="basic">
                        <ul class="basictools">
                            @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0)
                            {
                                if (Model.Question.CreatedUser == ViewBag.CurrentUserInfo.UserID || 
                                    ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.EditPost)
                                {
                                    <li>@Html.ActionLink(QAS_Nekorama.EDIT, "Edit", "Question", 
                                        new {questionId = @Model.Question.QuestionID}, new {@class = "edit-question-btn", id = "edit-question-btn"})</li>
                                }
                                if (ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Moderator)
                                {
                                    <li>@Html.ActionLink(QAS_Nekorama.DELETE, null, null, 
                                        new {user = @currentuser, id = @Model.Question.QuestionID}, new {@class = "delete-question-btn", id = "delete-question-btn"})</li>
                                }
                                if (ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Report && 
                                    WebSecurity.CurrentUserId != Model.Question.CreatedUser && !Helper.IsInString(WebSecurity.CurrentUserId, Model.Question.SpamMarkUserList))
                                {
                                    <li>@Html.ActionLink(QAS_Nekorama.REPORT, null, null, new {id = @Model.Question.QuestionID}, 
                                        new {@class = "report-question-btn", id = "report-question-btn"})</li>
                                }
                            }
                        </ul>
                    </div>
                    <!--end basic-->
                </div>
                <!--end manage-->
            </div>
            <!--end a-question-->
        </div>
        <!--end primary-2-->

        <div id="primary-3">
            <div class="answer-list">
                @if (Model.Answers.Count != 0)
                {
                    <h1>@Model.Answers.Count(a => a.IsDeleted != true && a.IsSpam == false) @QAS_Nekorama.ANSWERS_LOWER</h1>
                    foreach (Answer a in Model.Answers.Where(a => a.IsSpam == false && a.IsDeleted == false))
                    {
                    <div class="answer">
                        <div class="post-info">
                            <div class="profile">
                                    <a href="@Url.Action("Details", "User", new {id = a.CreatedUser}, null)">
                                    <img src="/Images/Avatars/@Helper.GetUserInfo(a.CreatedUser).Avatar" /></a>
                                    <h4>@Html.ActionLink(Helper.GetUserInfo(a.CreatedUser).DisplayName, 
                                        "Details", "User", new {id = a.CreatedUser}, null)</h4>
                            </div>
                            <!--end profile-picture-->

                            <div class="rate">
                                    @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && 
                                        ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.VoteDown && WebSecurity.CurrentUserId != a.CreatedUser)
                                {
                                    if (!Helper.IsInString(WebSecurity.CurrentUserId, a.VoteUpUserList))
                                    {
                                    <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" onclick=" vote(@a.AnswerID, true, false) " />
                                    }
                                    else
                                    {
                                    <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" style="-webkit-filter: grayscale(0);" />
                                    }

                                    <p>@a.VoteCount</p>
                                    if (!Helper.IsInString(WebSecurity.CurrentUserId, a.VoteDownUserList))
                                    {
                                    <img src="~/Images/Question-Details/votedown.png" class="votedown-btn" onclick=" vote(@a.AnswerID, false, false) " />
                                    }
                                    else
                                    {
                                    <img src="~/Images/Question-Details/votedown.png" class="votedown-btn" style="-webkit-filter: grayscale(0);" />
                                    }
                                }
                                else
                                {
                                        if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && 
                                            ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.VoteUp && WebSecurity.CurrentUserId != a.CreatedUser)
                                    {
                                        if (!Helper.IsInString(WebSecurity.CurrentUserId, a.VoteUpUserList))
                                        {
                                    <img src="~/Images/Question-Details/voteup.png" class="voteup-btn" onclick=" vote(@a.AnswerID, true, false) " />
                                        }
                                        else
                                        {<img src="/Images/Question-Details/voteup.png" class="voteup-btn" style="-webkit-filter: grayscale(0);" />
                                        }

                                    <p>@a.VoteCount</p>
                                    <img src="/Images/Question-Details/votedown.png" class="votedown-btn" style="-webkit-filter: grayscale(0);" />
                                    }
                                    else
                                    {
                                    <img src="/Images/Question-Details/voteup.png" class="voteup-btn" style="-webkit-filter: grayscale(0);" />
                                    <p>@a.VoteCount</p>
                                    <img src="/Images/Question-Details/votedown.png" class="votedown-btn" style="-webkit-filter: grayscale(0);" />
                                    }
                                }

                                <p></p>
                                @if (Helper.HasAcceptedAnswer(Model.Question.QuestionID))
                                {
                                    if (a.IsAccepted == true)
                                    {
                                    <p>
                                        <img src="/Images/Question-Details/accepted_button.png" alt="nekorama accepted" style="-webkit-filter: grayscale(0);" />
                                    </p>
                                    }
                                }

                                else
                                {
                                    if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && 
                                        ViewBag.CurrentUserInfo.UserID == Model.Question.CreatedUser && WebSecurity.CurrentUserId != a.CreatedUser)
                                    {
                                            <p>@Html.ActionLink("Accept", null, null, null, new {@class = "accept-btn", id = @a.AnswerID})</p>
                                    }
                                }
                                @for (int i = 0; i < a.SpamCount; i++)
                                {
                                    <img src="~/Images/Question-Details/report-img.png" style="width: 30px;" />
                                }
                            </div>
                            <!--end rate-->
                        </div>

                        <div class="post-detail">
                            <!--Answer content-->
                            <br />
                            <div style="word-wrap: break-word; min-height: 170px;">@Html.Raw(a.Content)</div>
                            @if (a.LastModifiedDate != null)
                            {
                                <p style="font-size: 10px; font-style: italic;">@QAS_Nekorama.LAST_EDIT_TIME at 
                                    @a.LastModifiedDate @Helper.GetUserInfo(a.ModifiedUser ?? 0).DisplayName<br />
                                    Reason: @Html.Raw(a.EditReason)
                                </p>
                            }
                        </div>
                        <!--end post-detail-->

                        <!--COMMENT-->
                        @if (a.Comments.Count != 0)
                        {
                            <div class="comment_list">
                                <div class="accordion">
                                    <h3>@QAS_Nekorama.COMMENT_S</h3>
                                    <div>
                                        @foreach (Comment c in a.Comments)
                                        {
                                            <div class="comment">
                                                    <h1>@Html.ActionLink(Helper.GetUserInfo(c.CreatedUser).DisplayName, 
                                                        "Details", "User", new {id = c.CreatedUser}, null)</h1>
                                                <p>@Html.Raw(Helper.Html2Text(c.Content))</p>
                                            </div>
                                            <!--end comment-->
                                        }
                                            @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && 
                                                ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Comment)
                                        {
                                            <div class="comment_tools">
                                                <textarea class="post-content" placeholder='@QAS_Nekorama.ENTER_COMMENT' name="comment-textbox" cols ="70" rows="3" id="answer-comment-content-@a.AnswerID"></textarea>
                                                    @Html.ActionLink(QAS_Nekorama.COMMENT, null, null, new {@class = "comment-btn", @onclick = "postComment(" + a.AnswerID + ",event)"})
                                            </div>
                                            <!--end comment_tools-->
                                        }
                                    </div>
                                </div>
                                <!--end accordion-->
                            </div>
                            <!--end comment_list-->
                        }
                        else
                        {
                                if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0 && 
                                    ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Comment)
                            {
                            <div class="comment_list">
                                <div class="accordion">
                                    <h3>@QAS_Nekorama.COMMENT_S</h3>
                                    <div>

                                        <div class="comment_tools">
                                            <textarea class="post-content" placeholder='@QAS_Nekorama.ENTER_COMMENT' 
                                                name="comment-textbox" cols ="70" rows="3" id="answer-comment-content-@a.AnswerID"></textarea>
                                                    @Html.ActionLink(QAS_Nekorama.COMMENT, null, null, new {@class = "comment-btn", @onclick = "postComment(" + a.AnswerID + ",event)"})
                                        </div>
                                        <!--end comment_tools-->
                                    </div>
                                </div>
                                <!--end accordion-->
                            </div>}
                            <!--end comment_list-->
                        }
                        <!--END COMMENT-->

                        <div class="manage">
                            <div class="basic">
                                <ul class="basictools">
                                    @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0)
                                    {
                                            if (a.CreatedUser == ViewBag.CurrentUserInfo.UserID || ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.EditPost)
                                        {
                                                <li>@Html.ActionLink(QAS_Nekorama.EDIT, null, null, new {@class = "edit-btn", @id = +a.AnswerID})</li>
                                        }
                                            if (a.IsAccepted != true && (ViewBag.CurrentUserInfo.Reputation >= (int) Constants.Privileges.Moderator))
                                        {
                                                <li>@Html.ActionLink(QAS_Nekorama.DELETE, null, null, new {user = @currentuser, id = @a.AnswerID}, new {@class = "delete-btn", @id = +a.AnswerID})</li>
                                        }
                                        if (a.CreatedUser != ViewBag.CurrentUserInfo.UserID && ViewBag.CurrentUserInfo.Reputation >= 500 && !Helper.IsInString(WebSecurity.CurrentUserId, a.SpamMarkUserList))
                                        {
                                                <li>@Html.ActionLink(QAS_Nekorama.REPORT, null, null, new {@class = "report-btn", @id = +a.AnswerID})</li>
                                        }
                                    }
                                </ul>
                            </div>
                            <!--end basic-->
                        </div>
                        <!--end manage-->
                    </div>
                    <!--end answer-->
                    }
                }

                <form id="valans">
                    @if (User.Identity.IsAuthenticated && ViewBag.CurrentUserInfo.BanDuration == 0)
                    {
                        <div class="text-editor">
                            <textarea name="textarea" wrap="hard" class="jqte-test" id="answer-content"></textarea>
                        </div>
                        <div style="text-align: right;">
                            @Html.ActionLink(QAS_Nekorama.POST_ANSWER, null, null, new {@class = "answer-btn", @onclick = "postAnswer(event);"})
                        </div>
                    }
                </form>
                <!--end text-editor-->
            </div>
            <!--end answer-list-->
        </div>
        <!--end primary-3-->
    </div>
    <!--end primary-->
    <script>
        $(document).ready(function() {
            $("#valans").validationEngine('attach', { promptPosition: "centerRight", scroll: false });
            $('.commentform').validationEngine('attach', { promptPosition: "centerRight", scroll: false });
            $('textarea').addClass("validate[[required],min[20]]");
            $('#bountyform').validationEngine('attach', { promptPosition: "centerLeft", scroll: false });
        });
    </script>

    <script>
        $(function() {
            $(".accordion").accordion({
                collapsible: true,
                active: false,
                heightStyle: "content",
                autoheight: true,
                widthStyle: "content",
                autowidth: true,
                clearStyle: true
            });
        });
    </script>
    <script type="text/javascript">

        function postComment(fromAnswer, event) {
            var newcmt = new Object();
            newcmt.QuestionID = '@Model.Question.QuestionID';
            newcmt.AnswerID = null;
            newcmt.CreatedUser = '@currentuser';

            var valid = false;
            if (fromAnswer == null) {
                newcmt.Content = $('#question-comment-content').val();
                if (newcmt.Content.trim().length < 20) {
                    $("#question-comment-content").validationEngine('showPrompt', '@Messages.COMMENT_LENGTH', 'error', 'bottomLeft', true);
                    event.preventDefault();
                } else {
                    valid = true;
                }

            } else {
                newcmt.Content = $('#answer-comment-content-' + fromAnswer).val();
                newcmt.AnswerID = fromAnswer;
                newcmt.QuestionID = null;
                if (newcmt.Content.trim().length < 20) {
                    $("#answer-comment-content-" + fromAnswer).validationEngine('showPrompt', '@Messages.COMMENT_LENGTH', 'error', 'bottomLeft', true);
                    event.preventDefault();
                } else {
                    valid = true;
                }
            }
            if (valid) {
                newcmt.CreatedDate = '@DateTime.Now';
                $.ajax({
                    type: 'POST',
                    url: '/Question/Comment',
                    data: JSON.stringify(newcmt),
                    async: false,
                    contentType: 'application/json; charset=utf-8',
                    cash: false,
                    success: null
                });
            }

        }

        function postAnswer(event) {
            var content = $("#answer-content").val();
            content = content.replace(/&nbsp;/g, "");
            if (content.trim().length < 30) {
                $(".jqte_editor").validationEngine('showPrompt', '@Messages.ANSWER_CONTENT_LENGTH', 'error', 'centerRight', true);
                    event.preventDefault();
                    return false;
                } else {
                    $(".jqte").removeClass("validate[[required],min[30]]");
                    $(".jqte").validationEngine('hideAll');
                    var newans = new Object();
                    newans.QuestionID = '@Model.Question.QuestionID';
                    newans.VoteCount = 0;
                    newans.createduser = '@currentuser';
                    newans.isAccepted = false;
                    newans.spamcount = 0;
                    newans.isdeleted = false;
                    newans.isspam = false;
                    newans.Content = content;
                    $('#answer-content').val("");
                    newans.CreatedDate = '@DateTime.Now';
                    $.ajax({
                        type: 'POST',
                        url: '/Question/Answer',
                        async: false,
                        data: JSON.stringify(newans),
                        contentType: 'application/json; charset=utf-8',
                        cash: false,
                        success: null,
                    completed: null
                    });
                }

            }

            function vote(id, pos, isquestion) {
                var voteobj = new Object();
                voteobj.voter = '@currentuser';
                //change to currently logged in user
                voteobj.targetID = id;
                voteobj.IsPositive = pos;
                voteobj.IsQuestion = isquestion;
                var request = $.ajax({
                    type: 'POST',
                    url: '/Question/Vote',
                    async: false,
                    data: JSON.stringify(voteobj),
                    contentType: 'application/json; charset=utf-8',
                    cash: false,
                    success: null,
                    completed: location.reload()
                });
                request.error(function(jqXHR, textStatus) {
                    alert("Request failed: " + textStatus);
                });
            }

            function setbounty(event) {
                event.preventDefault();
            var valid = false;
                var amt = $('#bountyamount').val();
            if ($.isNumeric(amt) == false || amt < @Constants.BOUNTY_MINIMUM || amt > @Constants.BOUNTY_MAXIMUM) {
                    valid = false;
                $('#bountyamount').validationEngine('showPrompt', '@Messages.BOUNTY_RANGE', 'error', 'bottomLeft', true);
            } else if (amt > @Helper.GetReputation(WebSecurity.CurrentUserName)- 1) {
                    valid = false;
                $('#bountyamount').validationEngine('showPrompt', '@Messages.NOT_ENOUGH_PERMISSION', 'error', 'bottomLeft', true);
            } else {
                    valid = true;
                }

            if (valid) {
                var bounty = new Object();
                bounty.CreatedUser = '@currentuser';
                bounty.QuestionID = '@Model.Question.QuestionID';
                bounty.AnswerID = null;

                bounty.lastModifiedDate = null;
                bounty.ModifiedUser = null;
                bounty.Amount = $("#bountyamount").val();

                bounty.CreatedDate = '@DateTime.Now';
                bounty.duration = @Constants.BOUNTY_DURATION;

                $.ajax({
                    type: 'POST',
                    url: '/Question/SetBounty',
                    async: false,
                    data: JSON.stringify(bounty),
                    contentType: 'application/json; charset=utf-8',
                    cash: false,
                    success: null,
                    complete: location.reload()
                });
            }

        }
    </script>

    <script type="text/javascript">
        $(".edit-btn").live("click", function(e) {
            e.preventDefault();
            var id = $(this).attr("id");
            var url = "/Question/EditPartial" + "?answerID=" + id;
            $("#editanswer-dialog").dialog({
                title: 'Edit Answer',
                closeOnEscape: true,
                autoOpen: false,
                resizable: false,
                height: 335,
                width: 735,
                show: { effect: 'drop', direction: "up" },
                modal: false,
                draggable: true,
                open: function(event, ui) {
                    $("#editanswer-dialog").load(url);

                },
                close: function(event, ui) {
                    $(this).dialog('close');
                }
            });

            $("#editanswer-dialog").dialog('open');
            return false;
        });
    </script>

    <script type="text/javascript">
        $(".accept-btn").live("click", function(e) {
            e.preventDefault();
            var id = $(this).attr("id");
            var user = '@WebSecurity.CurrentUserId';
            var data = new Object();
            data.answerId = id;
            data.userId = user;
            var url = "/Question/AcceptAnswer/";
            $("#dialog-accept").dialog({
                title: 'Accept Answer',
                closeOnEscape: true,
                autoOpen: false,
                resizable: false,
                height: 170,
                width: 350,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                buttons: {
                    "OK": function() {
                        $.ajax({
                            type: 'POST',
                            url: url,
                            async: false,
                            data: JSON.stringify(data),
                            contentType: 'application/json; charset=utf-8',
                            cash: false,
                            success: null,
                            completed: location.reload()
                        });
                        $(this).dialog("close");
                    },
                    "Cancel": function() {
                        $(this).dialog("close");
                    }
                }
            });

            $("#dialog-accept").dialog('open');
            return false;
        });
    </script>

    <script type="text/javascript">
        $("#delete-question-btn, .delete-btn").live("click", function(e) {
            e.preventDefault();
            var delq = false;
            if ($(this).hasClass("delete-question-btn")) {
                delq = true;
                var id = '@Model.Question.QuestionID';
                var data = { userId: '@currentuser', questionId: id };

                var url = "/Question/Delete/" + id;
            } else {
                var id = $(this).attr("id");
                var data = { userId: '@currentuser', answerId: id };
                var url = "/Question/DeleteAnswer/" + id;
            }
            if (delq) {
                $("#dialog-confirm").dialog({
                    autoOpen: false,
                    resizable: false,
                    closeOnEscape: true,
                    height: 170,
                    width: 350,
                    show: { effect: 'drop', direction: "up" },
                    modal: true,
                    draggable: true,
                    buttons: {
                        "OK": function() {
                            $.ajax({
                                type: 'POST',
                                url: url,
                                async: false,
                                data: JSON.stringify(data),
                                contentType: 'application/json; charset=utf-8',
                                cash: false,
                                success: location.reload(),
                                completed: null                                                               
                            });
                            $(this).dialog("close");
                        },
                        "Cancel": function() {
                            $(this).dialog("close");

                        }
                    }
                });
            } else {
                $("#dialog-confirm").dialog({
                    autoOpen: false,
                    resizable: false,
                    closeOnEscape: true,
                    height: 170,
                    width: 350,
                    show: { effect: 'drop', direction: "up" },
                    modal: true,
                    draggable: true,
                    buttons: {
                        "OK": function() {
                            $.ajax({
                                type: 'POST',
                                url: url,
                                async: false,
                                data: JSON.stringify(data),
                                contentType: 'application/json; charset=utf-8',
                                cash: false,
                                success: null,
                                completed: location.reload()
                            });
                            $(this).dialog("close");
                        },
                        "Cancel": function() {
                            $(this).dialog("close");

                        }
                    }
                });
            }

            $("#dialog-confirm").dialog('open');
            return false;
        });
    </script>

    <script type="text/javascript">
        $("#report-question-btn, .report-btn").live("click", function(e) {
            e.preventDefault();
            if ($(this).hasClass("report-btn")) {
                var reportModel = new Object();
                reportModel.reporterID = @WebSecurity.CurrentUserId;
                reportModel.targetID = $(this).attr("id");
                var url = "/Question/ReportAnswer";
            } else {
                var reportModel = new Object();
                reportModel.targetID = '@Model.Question.QuestionID';
                reportModel.reporterID = @WebSecurity.CurrentUserId;
                var url = "/Question/Report";
            }
            $("#dialog-report").dialog({
                autoOpen: false,
                resizable: false,
                closeOnEscape: true,
                height: 170,
                width: 350,
                show: { effect: 'drop', direction: "up" },
                modal: true,
                draggable: true,
                buttons: {
                    "OK": function() {
                        $.ajax({
                            type: 'POST',
                            url: url,
                            async: false,
                            data: JSON.stringify(reportModel),
                            contentType: 'application/json; charset=utf-8',
                            cash: false,
                            success: null,
                            complete: location.reload()
                        });
                        $(this).dialog("close");
                    },
                    "Cancel": function() {
                        $(this).dialog("close");

                    }
                }
            });

            $("#dialog-report").dialog('open');
            return false;
        });
    </script>

    <script>
        $('.jqte-test').jqte({placeholder: '@QAS_Nekorama.ENTER_ANSWER'});      
    </script>
}
else
{
    <div id="primary">
        <div id="primary-1">
        </div>
        <!--end primary-1-->

        <div id="primary-2">
            <div class="error">
                    <img src="~/Images/error-warning.png" />
                    <h1>@Messages.CONTENT_NOT_AVAILABLE</h1>
                </div>
            <script>
                setTimeout(function() { window.location = '@Url.Action("Index")'; }, 3000);
            </script>
        </div>
        <!--end primary-2-->
    </div>
    <!--end primary-->
}

<div style="display: none">
    <div id="dialog-confirm">
        <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
            @Messages.DELETE_CONFIRM
        </p>
    </div>

    <div id="editanswer-dialog" title="Edit answer">
    </div>

    <div id="dialog-report">
        <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
            @Messages.REPORT_CONFIRM
        </p>
    </div>

    <div id="dialog-accept">
        <p>
            <span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>
            @Resources.Messages.ANSWER_ACCEPT_CONFIRM
        </p>
    </div>
</div>